package ewa

import (
	//"net/http"
  "fmt"
	"github.com/labstack/echo"
)

type RestrictRouteCb func(echo.Context) error

/* Restrict Route POST, 
   需要cookies, 
   需要token验证  */
func CbCookieTokenPost(c echo.Context) error {
  //fmt.Printf("Path: %s\n", c.Path())	//such like as '/test.html'
  utype, uri := HttpReqPathSuffix(c.Path())

  if utype == URITYPE_RES {

  }else if utype == URITYPE_API {
      // API
      if uri == CfgRoute.ApiAddUser {
        UserAdd(c)
      }else if uri == CfgRoute.ApiChangePass {
        UserChangePass(c)
      }else {
        // 
        if CfgRoute.MApiAttr[uri].SyncAck == true {
          return SyncApiResponse(uri, c)
        }else{
          return AsyncApiResponse(uri, c)
        }
      }
  }
  return nil
}

func RouteRegistry_CookieTokenPost(route string, e *echo.Echo, cb RestrictRouteCb) {
  l:=fmt.Sprintf("----Echo/> regist CookieTokenPost '%s'", route);Log(l)
	e.POST(route, (echo.HandlerFunc)(cb))
}